package client

import (
	"gitee.com/baizhige/go-server-tempalte/common/constant"
	"gitee.com/baizhige/go-server-tempalte/common/log"
	"github.com/gin-gonic/gin"
)

func GetId(traceID string, c *gin.Context) (clientId string, err error) {
	//获取客户端ID
	clientId = c.GetHeader(constant.HeaderClientId)
	if clientId == "" {
		log.ErrorTF(traceID, "Client id not find")
		err = constant.ErrClientIdNotFind
		return
	}
	return
}

// GetIP 获取客户端IP
// 如果你的应用部署在代理服务器或负载均衡器后面，确保这些中间件正确地设置了X-Forwarded-For和X-Real-IP头。否则，c.ClientIP()可能无法正确获取客户端的真实IP。
func GetIP(traceID string, c *gin.Context) (clientIp string) {
	clientIp = c.ClientIP()
	return
}
